﻿using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Threading;
using System.Globalization;
using University.Workshop.DataAccess.LanguagePack.ClientLanguagePack;
using System.Collections.ObjectModel;
using University.Workshop.Business;
using System;

namespace University.Workshop.ClientApp.PokerGame.Transaction
{
    /// <summary>
    /// Interaction logic for PokerGameConsultingHistory.xaml
    /// </summary>
    public partial class PokerGameConsultingHistory : Window
    {        
        //The class Transaction need to be in Model not in the DataAccess
        
        private TransactionConsultManager ConsultTransaction;
        private string LanguageSelected;
        private string UserName;

        private string TextBlockMessagesSelectAnOption;

        private string ComboBoxConsultTypeBothTransfer;
        private string ComboBoxConsultTypeReceivedTransfer;
        private string ComboBoxConsultTypeSendTransfer;


        public PokerGameConsultingHistory()
        {
            InitializeComponent();

            try
            {
                this.ConsultTransaction = new TransactionConsultManager();
                this.ConsultTransaction.TransactionSendManagerConnectClient();
            }
            catch(Exception exception)
            {
                MessageBox.Show(exception.Message, ":-(");
                this.Close();
            }
        }

        public PokerGameConsultingHistory(string Language)
        {
            InitializeComponent();

            this.LanguageSelected = Language;
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(this.LanguageSelected);
            ApplyLanguage();

            ComboBoxConsultTypeAddItems();
            this.TextBlockMessages.Text = TextBlockMessagesSelectAnOption;

            try
            {
                this.ConsultTransaction = new TransactionConsultManager();
                this.ConsultTransaction.TransactionSendManagerConnectClient();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, ":-(");
                this.Close();
            }
        }

        public PokerGameConsultingHistory(string Language, string UserName)
        {
            InitializeComponent();

            this.LanguageSelected = Language;
            this.UserName = UserName;

            Thread.CurrentThread.CurrentUICulture = new CultureInfo(this.LanguageSelected);
            ApplyLanguage();

            ComboBoxConsultTypeAddItems();
            this.TextBlockMessages.Text = TextBlockMessagesSelectAnOption;

            try
            {
                this.ConsultTransaction = new TransactionConsultManager();
                this.ConsultTransaction.TransactionSendManagerConnectClient();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, ":-(");
                this.Close();
            }
        }

        private void ButtonCloseClick(object sender, RoutedEventArgs e)
        {
            this.Close();
        }


        private void ComboBoxConsultTypeAddItems()
        {
            this.ComboBoxConsultType.Items.Add(this.ComboBoxConsultTypeBothTransfer);
            this.ComboBoxConsultType.Items.Add(this.ComboBoxConsultTypeReceivedTransfer);
            this.ComboBoxConsultType.Items.Add(this.ComboBoxConsultTypeSendTransfer);
        }

        private void ComboBoxConsultTypeSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //Both table
            if (ComboBoxConsultType.SelectedIndex == 0)
            {
                this.TextBlockMessages.Text = this.ComboBoxConsultTypeBothTransfer;
                this.DataGridTransactions.ItemsSource = this.ConsultTransaction.BothTransaction(this.UserName);
            }

            //Received table
            if (ComboBoxConsultType.SelectedIndex == 1)
            {                
                this.TextBlockMessages.Text = this.ComboBoxConsultTypeReceivedTransfer;                
                this.DataGridTransactions.ItemsSource = this.ConsultTransaction.ReceiveTransaction(this.UserName);                
            }

            //Send table
            if (ComboBoxConsultType.SelectedIndex == 2)
            {
                this.TextBlockMessages.Text = this.ComboBoxConsultTypeReceivedTransfer;
                this.DataGridTransactions.ItemsSource = this.ConsultTransaction.SendTransaction(this.UserName);                
            }
        }


        private void ApplyLanguage()
        {
            //Labels content
            this.Title = ClientLanguagePack.PokerGameConsultingHistoryTitle;
            this.LabelConsultingType.Content = ClientLanguagePack.PokerGameConsultingHistoryLabelConsultingType;
            this.TextBlockMessagesSelectAnOption = ClientLanguagePack.PokerGameConsultingHistoryTextBlockMessagesSelectAnOption;

            //Button content
            this.ButtonClose.Content = ClientLanguagePack.PokerGameConsultingHistoryButtonClose;

            //ComboBox Items
            this.ComboBoxConsultTypeBothTransfer = ClientLanguagePack.PokerGameConsultingHistoryComboBoxConsultTypeBothTransfer;
            this.ComboBoxConsultTypeReceivedTransfer = ClientLanguagePack.PokerGameConsultingHistoryComboBoxConsultTypeReceivedTransfer;
            this.ComboBoxConsultTypeSendTransfer = ClientLanguagePack.PokerGameConsultingHistoryComboBoxConsultTypeSendTransfer;
        }

        private void DataGridTransactions_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }
    }
}
